package Shopping;
import java.util.Scanner;

public class ShoppingCartSystem {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        Product[] products = {
                new Product("雪碧", "饮料", 3.5, 50),
                new Product("可乐", "饮料", 4.0, 30),
                new Product("果汁", "饮料", 5.0, 20),
                new Product("苹果", "水果", 3.0, 100),
                new Product("香蕉", "水果", 2.0, 80)
        };

        ShoppingCart cart = new ShoppingCart();

        while (true) {
            System.out.println("\n====================购物车系统====================");
            System.out.println("1. 查看商品列表");
            System.out.println("2. 添加商品到购物车");
            System.out.println("3. 查看购物车");
            System.out.println("4. 删除购物车中的商品");
            System.out.println("5. 结算");
            System.out.println("6. 退出");
            System.out.print("请选择操作（1-6）：");

            int choice = scanner.nextInt();
            scanner.nextLine();

            if (choice == 1) {
                System.out.println("\n可选商品：");
                for (int i = 0; i < products.length; i++) {
                    System.out.println((i + 1) + ". " + products[i].name + " - ¥" + products[i].price);
                }
            } else if (choice == 2) {
                System.out.print("请输入商品编号：");
                int productIndex = scanner.nextInt() - 1;

                if (productIndex >= 0 && productIndex < products.length) {
                    cart.addProduct(products[productIndex]);
                } else {
                    System.out.println("无效的商品编号！");
                }
            } else if (choice == 3) {
                cart.viewCart();
            } else if (choice == 4) {
                System.out.print("请输入要删除的商品名称：");
                String productName = scanner.nextLine();
                cart.removeProduct(productName);
            } else if (choice == 5) {
                cart.checkout();
                break;
            } else if (choice == 6) {
                System.out.println("感谢使用购物车系统！");
                break;
            } else {
                System.out.println("无效选择，请重新输入！");
            }
        }

        scanner.close();
    }
}

